The Let's Play Archive

Compute!'s Gazette

by Chokes McGee

Part 32: FredMSloniker - Hex Wars Redux - Part 2

Tuning up Hex War: Part 2



When you start a game of Hex War, you're presented with a screen that looks something like this. (If you're playing with capital cities, they appear as crosses.) The purple forces are arranged at the bottom, and the blue forces at the top. Purple always gets the first -

- wait, purple and yellow versus blue and green? Who chose these team colors? A big Seahawks and Huskies fan? What if I don't like these options?

Fortunately, it's not too difficult to fix. We just have to hack the code a bit. But first, a picture.



These are the 16 colors available to us on a Commodore 64. Before we can change the colors of the armies, we have to first locate where those colors are in the code. There are three forms in which they show up:
So for each of the four colors we want to be able to change, we need a color code, which is a character. For the two primary piece colors, we also need their number and their name. Once we have those, we need to substitute them into the appropriate spots.

At some point, I should probably allow players to choose their piece colors, but for right now I added some constants that we can change to change the army colors. The first point at which the colors matter is line 60, which defines strings that we print to make the units. We get there from line 50, which means we have nine lines worth of room to work with. Here's the code:
code:
51 P0=4:P1=6:P2=13:P3=7:REM DEFAULT ARMY COLORS
52 PC$="{black}{white}{red}{cyan}{purple}{green}{blue}{yellow}
   {orange}{brown}{lt. red}{gray1}{gray2}{lt. green}{lt. blue}{gray3}"
53 C0$=MID$(PC$,P0+1,1):C1$=MID$(PC$,P1+1,1)
54 C2$=MID$(PC$,P2+1,1):C3$=MID$(PC$,P3+1,1)
55 DATA"BLACK","WHITE","RED","CYAN","PURPLE","GREEN","BLUE","YELLOW"
56 DATA"ORANGE","BROWN","PINK","DK.GRAY","MD.GRAY","LIME","INDIGO","LT.GRAY"
57 DIMPC$(15):FORZZ=0TO15:READPC$(ZZ):NEXT
58 N0$=PC$(P0):N1$=PC$(P1)
(EDIT: I broke line 52 to stop breaking tables. This line, and any future lines I break, do not have any whitespace at the break.)

So, let's explain. Line 51 is where we set the army colors; P0 and P1 are the primary colors of the two players (player 2 is player 0 internally), while P2 and P3 are the secondary colors of players 0 and 1, respectively.

Line 52 isn't actually full of curly brackets; it contains the 16 color codes used by the Commodore 64 to change colors while printing. Lines 53 and 54 grab the codes associated with the numbers in P0 to P3 and assign them to C0$ to C3$ respectively.

Lines 55 and 56 contain names for the 16 colors, which are read into an array in line 57. Then line 58 puts the names for the two primary colors into N0$ and N1$.

So now I had all the bits I needed. Where did I put them in the program? As I said, the first occurence is line 60:
code:
60 A=RND(-TI/97):P0$="{blue}{rvrs off}{$af:2}{down}{left:2}{lt. green}{$df}
   {ctrl pound}":P1$="{yellow}{rvrs on}{ctrl pound}{$df}{rvrs off}{down}
   {left:2}{purple}{$b7:2}"
So I replaced the hard-coded colors, like so:
code:
60 A=RND(-TI/97):P0$=C0$+"{rvrs off}{$af:2}{down}{left:2}"+C2$+"{$df}
   {ctrl pound}":P1$=C3$+"{rvrs on}{ctrl pound}{$df}{rvrs off}{down}{left:2}"
   +C1$+"{$b7:2}"
The next place color codes were used was in lines 310 and 320, where they were used to print the logo. (From here on in, I'm just showing the changed lines.)
code:
310 XC=6:YC=11:GOSUB1:PRINTC0$;"{rvrs on}  {$cc}{$a7}  {$cc}{$b7}  {$cd}
    {$ce}    {$a5}{$a7}  {$ce}{$cd}  {$cf}{$cd}  "
320 XC=6:YC=12:GOSUB1:PRINTC1$;"{rvrs on}  {$a5}{$a7}  {$cc}{$af}  {$ce}
    {$cd}    {$ce}{$cd}  {$cf}{$a7}  {$a5}{$cd}  {home}{red}{rvrs off}";
Then there was line 430, which changes the border to the color for the player whose turn it is. I had to do a little math for this:
code:
430 POKEC4,P0+PN*(P1-P0):GOSUB800:REM JOYSTICK
If PN is 0, this formula resolves to P0; if PN is 1, this formula resolves to P1.

Lines 680 and 690 set the cursor color before drawing the capital cities, if we're playing a game mode with capital cities:
code:
680 J=1:POKEC5,P0:IFGN=1THENC$=D$:GOSUB710:J=2:POKEC5,P1:GOSUB710
690 IFGN=2THENC$=D$:GOSUB710:J=3:POKEC5,P0:GOSUB710
Line 910 sets the cursor color before printing the statistics for an army unit:
code:
910 POKEC5,P0+Q1*(P1-P0):PRINT"{home}"QN:PRINT"{$c0:6}{rvrs off}{gray2}"
Just for completion's sake, I changed the remarks in lines 1540 and 1550:
code:
1540 DATA 64,2,8,64,3,7,64,5,6,64,6,6:REM PLAYER 1
1550 DATA 64,2,2,64,3,2,64,5,1,64,6,0:REM PLAYER 0
Line 1860 gets ready to print the strength of a given army in hex:
code:
1860 POKEC5,P0+A*(P1-P0):XC=E:YC=F+A:GOSUB1
Finally, several lines from 3430 on are used to print the color of who won (depending on the game conditions chosen):
code:
3430 IFMAP(CIT(2,0),CIT(2,1),1)=1THENA=2:C$=N1$+" CAPTURED THE CAPITAL":RETURN
3450 IFMAP(CIT(3,0),CIT(3,1),1)=1THENA=2:C$=N1$+" CAPTURED THE CAPITAL":RETURN
3460 IFMAP(CIT(1,0),CIT(1,1),1)=2THENA=1:C$=N0$+" CAPTURED THE CAPITAL"
3550 IF C(1)=> L THEN A=2:C$=N0$+" HAS CAPTURED"+STR$(C(1))+" CITIES":RETURN
3560 IF C(2)=> L THEN A=1:C$=N1$+" HAS CAPTURED"+STR$(C(2))+" CITIES"
3620 IF C(1)=>40THENA=2:C$=N0$+" OCCUPIES"+STR$(C(1))+" HEXES":RETURN
3630 IF C(2)=>40THENA=1:C$=N1$+" OCCUPIES"+STR$(C(2))+" HEXES"
And that's it! I could now change up the in-game colors.

Now, this first pass does have some flaws. Obviously it would be possible to choose colors that would make pieces invisible or look the same, but that's down to user error at this point. It also doesn't do anything about potential conflicts with the other colors used; for instance, the border changes colors between turns to indicate that the computer is processing. That's something I planned to tweak later.

I gave it a try by changing this line:
code:
51 P0=2:P1=6:P2=10:P3=14
And here's the result:



...oops.



To do list: